
#定义一个人类
class Ren:
    def __init__(self,name):
        self.name = name
        self.xue = 100
        self.qiang = None
    def __str__(self):
        return self.name + "剩余血量为：" + str(self.xue)
    def anzhidan(self,danjia,zhidan):
        danjia.baocunzidan(zhidan)
    def andanjia(self,qiang,danjia):
        qiang.lianjiedanjia(danjia)
    def naqiang(self,qiang):
        self.qiang = qiang
    def kaiqiang(self,diren):
        self.qiang.she(diren)
    def diaoxue(self,shashangli):
        self.xue -= shashangli
        

#定义一个弹夹类
class Danjia:
    def __init__(self,rongliang):
        self.rongLiang = rongliang
        self.rongLiangList = []
    def __str__(self):
        msg = "当前子弹为：" + str(len(self.rongLiangList)) + "/" + str(self.rongLiang)
        return msg

    def baocunzidan(self,zhidan):
        if len(self.rongLiangList) < self.rongLiang:
            self.rongLiangList.append(zhidan)
    def chuzidan(self):
        #判断当前弹夹是否还有子弹
        if len(self.rongLiangList) > 0:
            zhidan = self.rongLiangList[-1]
            self.rongLiangList.pop()

            return zhidan
        else:
            return None

#定义一个子弹类
class Zhidan:

    def __init__(self,shashangli):
        self.shashangli = shashangli

    def shanghai(self,diren):
        diren.diaoxue(self.shashangli)

#定义一个枪类
class Qiang:
    def __init__(self):
        self.danjia = None
    def __str__(self):
        if self.danjia:
            return "枪当前有弹夹"
        else:
            return "枪当前没有弹夹"
    def lianjiedanjia(self,danjia):
        if not self.danjia:
            self.danjia = danjia
    def she(self,diren):
        zidan = self.danjia.chuzidan()
        if zidan:
            zidan.shanghai(diren)
        else:
            print("没有子弹了，放了空枪....")
class Sandan(Qiang):
    #重写父类
    def she(self,diren):
        i=0
        while i<3:
            # zidan = self.danjia.chuzidan()
            # if zidan:
            #     zidan.shanghai(diren)
            # else:
            #     print("没有子弹了，放了空枪....")
            super().she(diren)
            i+=1

class AK47(Qiang):
    pass
class M4A1(Qiang):
    pass


laowang = Ren("laowang")

danjia = Danjia(20)
print(danjia)
i = 0
while i<5:
    zhidan = Zhidan(5)
    laowang.anzhidan(danjia,zhidan)
    i+=1
print(danjia)

qiang = Sandan()
print(qiang)
laowang.andanjia(qiang,danjia)
print(qiang)

#创建一个敌人
diren = Ren("敌人")
print(diren)
laowang.naqiang(qiang)
print(danjia)
laowang.kaiqiang(diren)
print(diren)
print(danjia)
laowang.kaiqiang(diren)
print(diren)
print(danjia)


print("="*40)
#公有，私有
class Person:
    def __init__(self,name,age):
        self.name = name
        self.__age = age
    def setNewAge(self,newAge):
        if newAge > 0 and newAge <= 100:
            self.__age = newAge
    def getAge(self):
        return self.__age
    def __del__(self):
        print("-------del-------")


print("="*40)

#单继承
class Cat(object):

    def run(self):
        print("-------跑--------")

class Bois(Cat):
    pass

bois = Bois()

bois.run()

print("="*40)
#多继承

class Ma(object):
    def pao(self):
        print("----pao-----")
    def jiao(self):
        print("------马在叫------")

class Lv(object):
    def tuo(self):
        print("----tuo-----")
    def jiao(self):
        print("------驴在叫------")
class Luozi(Lv,Ma):
    pass
class Xin(Luozi):
    pass

luozi = Xin()

luozi.pao()
luozi.tuo()
luozi.jiao()

print(Xin.__mro__)